<?php
$subNav = array();
$arr = explode("/", $_SERVER['PHP_SELF']);

$domain = substr($_SERVER['PHP_SELF'], 0, strlen($arr[1]) + 1);
set_include_path("../");
include("inc/essentials.php");
include("model/feedback.php");
include("model/daily.php");

$fb = count(FeedBack::findAll());

if (!isset($_GET["page"])) {
    $_page = 1;
} else {
    $_page = $_GET["page"];
}
$num_page = 5;
$numPage = ceil($fb / $num_page);
$showeachside = 5;
$eitherside = ($showeachside * 1);

if (empty($page))
    $start = 0;
else
    $start = $page;

$pageCurrent = $num_page * ($_page - 1);

$feedback = FeedBack::findAllLimit($pageCurrent, $num_page);
?>
<script>
    $mainNav.set("home")
</script>
<div id="bdwrapper">
    <div id="leftcontent">
        <div class="backcontent"><a href="javascript:history.back()"><img src="img/icons/backicon.png" /><span>Khách hàng nói về chúng tôi</span></a></div>
        <div class="clear"></div>
        <div class="contentnews">
            <div class="bigtitle">Khách hàng nói về chúng tôi</div>
            <div class="clear"></div>
            <?php
            foreach ($feedback as $_feedback) {
                $phone = substr($_feedback["phone"], 0, 6);
                ?>
                <div class="customer">
                    <div class="content">
                        <?php echo $_feedback["comments"] ?>
                    </div>
                    <div class="time">Gửi lúc: <?php echo date("h:s d/m/Y", $_feedback["time"]) ?></div>
                    <div class="name"><?php echo $_feedback["name"] ?> - <?php echo $phone . "xxx" ?> </div>
                </div>
            <?php } ?>
            <div class="clear"></div>
            <div class="form-paging-bg-top">
                <div class="total-result">
                    <p><b><?php echo $fb; ?> </b><t>results</t> <span>(<t>page</t> <?php echo $_page ?>/<?php echo $numPage ?>)</span></p>
                </div>
                <div class="result-paging">
                    <?php for ($i = 1; $i <= $numPage; $i++) { ?>
                        <?php if($i == $_page) { ?>
                        <a class="pagingItem current-page" value="1" href="javascript:void(0)"><?php echo $i; ?></a> 
                        <?php }else{ ?>
                        <a class="pagingItem {class}" value="1" href="<?php echo $domain . "/#!/url=customer_del.php?page={$i}"; ?>"><?php echo $i; ?></a> 
                        <?php } ?>
                    <?php } ?>
                    <?php if($_page < $numPage){ ?>
                        <a class="pagingItem {class}" value="2" href="<?php echo $domain . "/#!/url=customer_del.php?page=". ($_page+1); ?>">Tiếp theo</a> 
                        <a class="pagingItem {class}" value="30" href="<?php echo $domain . "/#!/url=customer_del.php?page={$numPage}"; ?>">Cuối cùng</a> 
                    <?php } ?>
                    
                </div>
            </div>
            <div class="clear"></div>
            <div class="formcustomer">
                <form action="" method="post">
                    <h5>HÃY ĐỂ LẠI nhận xét của bạn tại đây</h5>
                    <label>Tên bạn</label>
                    <input name="name" type="text" id="name" class="inputName">
                    <label>Phone</label>
                    <input name="phone" type="text" id="phone" class="inputName">
                    <label>Nhận xét</label>
                    <textarea name="comment" rows="5" cols="50" id="comment" class="messageKH"></textarea>
                    <input type="button" name="Send" value="Gửi" id="Send" class="submitMessage">
                </form></div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="rightcontent">
        <div class="searchbox">
            <div class="title">Đặt vé máy bay</div>
            <div class="line6"></div>
            <form action="http://127.0.0.1/abay/tim-kiem" method="post">
                <input type="radio" value="2" name="flightwaytype" class="sdb fl inp1" checked="checked"><span class="select label1 sdb fl" id="vl2">Khứ Hồi</span><input type="radio" value="1" name="flightwaytype" class="sdb fl inp1"><span class="label1 sdb fl" id="vl1">Một Chiều</span>
                <div class="clear"></div>
                <script language="javascript">
                    $('input[name="flightwaytype"]').click(function() {
                        value = $(this).val();
                        $('span[id="vl1"]').removeClass('select');
                        $('span[id="vl2"]').removeClass('select');
                        $('span[id="vl' + value + '"]').addClass('select');
                        if (value == 1) {
                            $('input[name="date_back"]').attr('disabled', 'disabled').val('').animate({opacity: 0.5}, 500);
                        } else {
                            $('input[name="date_back"]').removeAttr('disabled').animate({opacity: 1}, 500);
                        }
                    });
                </script>

                <span class="label2">
                    Khởi hành từ
                </span>
                <input type="text" name="go" class="input1 ac_input" autocomplete="off">
                <span class="label2">
                    Đến
                </span>
                <input type="text" name="to" class="input1 ac_input" autocomplete="off">

                <span class="label2 w50 fl">
                    Ngày xuất phát
                </span>
                <span class="label2 w50 fl">
                    Ngày xuất về
                </span>
                <div class="clear"></div>
                <input class="input1 w50 fl date hasDatepicker" name="date_go" id="dp1385203425343"><input class="input1 w50 fl date hasDatepicker" type="text" name="date_back" id="dp1385203425342">
                <div class="clear"></div>

                <span class="label2 w30 fl">
                    Người lớn
                </span>
                <span class="label2 w30 fl">
                    Trẻ em
                </span>
                <span class="label2 w30 fl">
                    Em bé
                </span>
                <div class="clear"></div>
                <select name="cboAdult" id="cboAdult" class="focus_input w30 fl">
                    <option selected="selected" value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </select>
                <select name="cboChild" id="cboChild" class="focus_input w30 padmid fl">
                    <option selected="selected" value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </select>
                <select name="cboInfant" id="cboInfant" class="focus_input w30 fl">
                    <option selected="selected" value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                </select>
                <div class="clear"></div>
                <input type="submit" value="Tìm chuyến bay" class="tvo_find">
            </form>
        </div>
        <div class="clear"></div>
        <div class="adleft">
            <img src="demo/bannerad.jpg" />
        </div>
        <div class="howto">
            <div class="title"><img src="img/icons/text.png" /><span>Tôi làm thế nào</span></div>
            <ul class="right_mnu">
                <li><a href="#" title="Liên Hệ" style="padding-left: 14px;">Liên Hệ</a></li>
                <li><a href="#" title="Thanh Toán" style="padding-left: 14px;">Thanh Toán</a></li>
                <li><a href="#" title="Xem Đơn Hàng">Xem Đơn Hàng</a></li>
            </ul>
        </div>
    </div>
    <div class="clearAll"></div>
    <ul class="listservice">
        <li><a <?php metroLink("search.php") ?>><img src="img/banner/dat-ve.jpg" width="178" height="132" /></a></li>
        <li><a <?php metroLink("search.php") ?>><img src="img/banner/thue-xe.jpg" width="178" height="132" /></a></li>
        <li><a <?php metroLink("search.php") ?>><img src="img/banner/datphong.jpg" width="178" height="132" /></a></li>
        <li><a <?php metroLink("search.php") ?>><img src="img/banner/dulich.jpg" width="178" height="132" /></a></li>
        <li><a <?php metroLink("search.php") ?>><img src="img/banner/dichvu.jpg" width="178" height="132" /></a></li>
    </ul>
</div>

<div class="clear"></div>
<div class="webfooter">
    <?php require_once 'tpl/sup/footer.php'; ?>
</div>
<script>
    $('#Send').click(function() {
        var name = $('#name').val();
        var phone = $('#phone').val();
        var comment = $('#comment').val();

        if (name == '') {
            alert('Họ tên không được để trống.');
            return false;
        }
        if (phone == '') {
            alert('Điện thoại không được để trống.');
            return false;
        }
        if (comment == '') {
            alert('Comment không được để trống.');
            return false;
        } else {
            $.ajax({
                // The link we are accessing.
                url: "<?php echo $domain ?>/ajax.php",
                // The type of request.
                type: "get",
                data: "act=add_feedback&name=" + name + "&phone=" + phone + "&comment=" + comment,
                // The type of data that is getting returned.
                dataType: "html",
                error: function() {
                    // Load the content in to the page.
                    $("#error").html("<label>Page Not Found!!</label>");
                    $("#error").css({display: "block"});
                },
                success: function(strData) {
                    // Load the content in to the page.
                    if (strData == "1") {
                        alert('Gửi phản hồi thành công.');
                    } else {
                        alert(strData);
                    }
                }
            });
        }
    });
</script>